function [] = main( )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
T = 1;v=0.1;

fl1n=zeros(1,4);
fl2n=zeros(1,4);
flin=zeros(1,4);
n=20
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = forward(T,n,v);
fl1n(1)=max(zl1n,rl1n);
fl2n(1)=max(zl2n,rl2n);
flin(1)=max(zlin,rlin);
n=40
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = forward(T,n,v);
fl1n(2)=max(zl1n,rl1n);
fl2n(2)=max(zl2n,rl2n);
flin(2)=max(zlin,rlin);
n=80
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = forward(T,n,v);
fl1n(3)=max(zl1n,rl1n);
fl2n(3)=max(zl2n,rl2n);
flin(3)=max(zlin,rlin);
n=160
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = forward(T,n,v);
fl1n(4)=max(zl1n,rl1n);
fl2n(4)=max(zl2n,rl2n);
flin(4)=max(zlin,rlin);

H=[1/20,1/40,1/80,1/160];

plot(log(H),log(fl1n));
title('L1-convegence-order-of-upwind');
h = gcf;
hgexport(h,'L1-convegence-order-of-upwind');

plot(log(H),log(fl2n));
title('L2-convegence-order-of-upwind');
h = gcf;
hgexport(h,'L2-convegence-order-of-upwind');

plot(log(H),log(fl2n));
title('L-infinity-convegence-order-of-upwind');
h = gcf;
hgexport(h,'L-infinity-convegence-order-of-upwind');

tau=v/n;
x=-1+1/2/n:1/n:1-1/2/n;
y=0:tau:1-tau;
contourf(x,y,rz');
title('Periodic-upwind-rou');
h = gcf;
hgexport(h,'Periodic-upwind-rou');
contourf(x,y,rr');
title('Riemann-upwind-rou');
h = gcf;
hgexport(h,'Riemann-upwind-rou');

n=20
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = laxwendrof(T,n,v);
fl1n(1)=max(zl1n,rl1n);
fl2n(1)=max(zl2n,rl2n);
flin(1)=max(zlin,rlin);
n=40
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = laxwendrof(T,n,v);
fl1n(1)=max(zl1n,rl1n);
fl2n(1)=max(zl2n,rl2n);
flin(1)=max(zlin,rlin);
n=80
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = laxwendrof(T,n,v);
fl1n(1)=max(zl1n,rl1n);
fl2n(1)=max(zl2n,rl2n);
flin(1)=max(zlin,rlin);
n=160
[ rz,uz,zl1n,zl2n,zlin,rr,ur,rl1n,rl2n,rlin ] = laxwendrof(T,n,v);
fl1n(1)=max(zl1n,rl1n);
fl2n(1)=max(zl2n,rl2n);
flin(1)=max(zlin,rlin);

plot(log(H),log(fl1n));
title('L1-convegence-order-of-lax-wendrof');
h = gcf;
hgexport(h,'L1-convegence-order-of-lax-wendrof');

plot(log(H),log(fl2n));
title('L2-convegence-order-of-lax-wendrof');
h = gcf;
hgexport(h,'L2-convegence-order-of-lax-wendrof');

plot(log(H),log(fl2n));
title('L-infinity-convegence-order-of-lax-wendrof');
h = gcf;
hgexport(h,'L-infinity-convegence-order-of-lax-wendrof');

tau=v/n;
x=-1+1/2/n:1/n:1-1/2/n;
y=0:tau:1-tau;
contourf(x,y,rz');
title('Periodic-Laxwendrof-rou');
h = gcf;
hgexport(h,'Periodic-Laxwendrof-rou');
contourf(x,y,rr');
title('Riemann-Laxwendrof-rou');
h = gcf;
hgexport(h,'Riemann-Laxwendrof-rou');
%contourf(rz');
%pause(1);
%contourf(uz');
%pause(1);

%周期函数的真解：

nn = 2*n;
h=1/n;
tau=h*v;
t = floor(T/tau);
rzR = zeros(nn,t+1);
uzR = zeros(nn,t+1);
for i=1:nn
    for j=1:t+1
        x = (i-n-1/2)*h;
        tt = tau*j-tau;
        rzR(i,j) = 2 + cos(pi*tt)*sin(pi*x)+sin(pi*tt)*sin(pi*x);
        uzR(i,j) = 2 + cos(pi*tt)*cos(pi*x)-sin(pi*tt)*cos(pi*x);
    end
end

%Riemann数据的真解：
nn = 2*n;
rrR = zeros(nn,t+1);
urR = zeros(nn,t+1);
for i=1:nn
    for j=1:t+1
        x = (i-n+1/2)*h;
        tt = tau*j-tau;
        if x<=-tt
            rrR(i,j) = 1;
        else if x <= tt
                rrR(i,j) = 4;
            else
                rrR(i,j) = 3;
            end
        end            
        if x<=-tt
            urR(i,j) = 5;
        else if x <= tt
                urR(i,j) = 2;
            else
                urR(i,j) = 1;
            end
        end            
    end
end
x=-1+1/2/n:1/n:1-1/2/n;
y=0:tau:1-tau;
contourf(x,y,rzR');
title('Periodic-Precise-rou');
h = gcf;
hgexport(h,'Periodic-Precise-rou');
contourf(x,y,rrR');
title('Riemann-Precise-rou');
h = gcf;
hgexport(h,'Riemann-Precise-rou');
end

